<?php
// classe de base, avec ses membres et ses méthodes
//test 2
class Gallery extends Controller{

    var $_defaultPage="index";
    var $_cssfile = "style.css";

    function Gallery() {
        parent::Controller();
        $this->load->model('gallery_model');
    }

    function index()
    {
        // Load the language file containing error messages
        //$this->lang->load('wiki');
        echo $this->config->item('language').'<br>';
        echo "gall : ".$this->lang->line('wiki_test').'<br>';
        echo site_url("");
    }
    /**
     * Returns all the infos related to a specific gallery
     * to be called from a flash animation only
     * the infos are serialized and url encoded 
     *
     * @param string $galname the gallery name (ie the directory name)
     */
    function getinfos($galname)
    {
        $this->load->helper('flash');
        $galinfos=$this->gallery_model->getGalleryData($galname);
        $galinfos['images']=array_values($galinfos['images']);
        echo send_to_flash($galinfos);
    }

    /**
     * Displays a specific gallery
     * different uses:
     * - use as a conventional web page with a pager that will reload the page with a new url
     * - use as an iframe gallery, the web page needs to be adjusted to remove all extra navigation items
     * - use as an ajax gallery, uses a specific template that will not reload when calling a new image
     *   when using the pager : a javascript will update the pager appearance and update the image src
     *   the infos should be serialized (json) to make them available in javascript, 
     *
     * @param string $galleryname
     * @param string $image
     */
    function show($galleryname,$image="1")
    {
        //test if the requested gallery exists
        //and if it's online

        //if there's no image argument
        //set it to 1

        //if image is set to "overview" or "thumbnails"
        //show all the images in the gallery
        //relates to a different template?

        //retreive infos from the gallery
        //set the template or use the default one
        $this->load->helper('javascript');
        $output['galname']=$galleryname;
        $output['currindex']=$image;
        $output['galinfos']=$this->gallery_model->getGalleryData($galleryname);
        $output['images']=array_values($output['galinfos']['images']);
        $output['jsongal']=json2(array_values($output['galinfos']['images']));
        $this->load->view("/gallery/show.html.php",$output);
    }

}
?>
